package com.fau.cm.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

import com.fau.cm.util.SystemConfig;

/**
 * @desc 联系记录表
 * @author yangzj
 * @datetime 2014年10月17日,下午5:21:43
 */
@Entity
@Table(name = "medical_call_contact_record")
public class MedicalCallContactRecord implements Serializable, JSONAware {

	private static final long serialVersionUID = -327408550312881455L;

	private String id; 							// 联系记录表id
	private String operatorId; 					// 话务人员id
	private String customerId;					// 客户id
	private String contactWay; 					// 联系方式(呼出/呼入) 1呼入、0呼出
	private Date contactTime = new Date(); 		// 联系时间
	private String remarks; 					// 备注
	private String operatorUser;				// 坐席
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@Column(name = "operator_id", length = 32)
	public String getOperatorId() {
		return operatorId;
	}

	public void setOperatorId(String operatorId) {
		this.operatorId = operatorId;
	}
	
	@Column(name = "customer_id", length = 32)
	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}

	@Column(name = "contact_way", length = 5)
	public String getContactWay() {
		return contactWay;
	}

	public void setContactWay(String contactWay) {
		this.contactWay = contactWay;
	}

	@Column(name = "contact_time", length = 32)
	public Date getContactTime() {
		return contactTime;
	}

	public void setContactTime(Date contactTime) {
		this.contactTime = contactTime;
	}

	@Column(name = "remarks", length = 255)
	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	@Transient
	public String getOperatorUser() {
		return operatorUser;
	}

	public void setOperatorUser(String operatorUser) {
		this.operatorUser = operatorUser;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("operatorUser", operatorUser);
		obj.put("contactTime", DateFormatUtils.format(contactTime,"yyyy-MM-dd HH:mm:ss"));
		if(SystemConfig.CONTACT_RECORD_INCOMING.equals(contactWay)) {
			obj.put("contactWay", "呼入");
		} else {
			obj.put("contactWay", "呼出");
		}
		obj.put("remarks", remarks);
		
		return obj.toString();
	}
}
